package thread_safe;

import thread.ThreadUtils;

public class Counter {
    public static int count = 0;

    public static void inc() {
        ThreadUtils.sleep(1);
        count++;
        System.out.println("count 的当前值为：" + count);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    Counter.inc();
                }
            });
            thread.start();
        }

        while (Thread.activeCount() > 2) {
            Thread.yield();
        }
        System.out.println("count 的最终值为：" + Counter.count);
    }
}
